package com.lwhtarena.netty.netty4.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FileInfoBuilder {


    public static FileInfo convertFile(String input){
        // 定义正则表达式
        String regex = "filename:(\\S+\\.(\\w+)),\\s+filesize:(\\d+)";

        // 编译正则表达式
        Pattern pattern = Pattern.compile(regex);

        // 创建 Matcher 对象
        Matcher matcher = pattern.matcher(input);

        // 查找匹配项
        if (matcher.find()) {
            // 提取 filename、文件格式 和 filesize
            String filename = matcher.group(1).replace(":","-");
            String fileFormat = matcher.group(2);
            String filesize = matcher.group(3);

            // 输出结果
            FileInfo fileInfo = new FileInfo(filename, fileFormat, Long.parseLong(filesize));
            return fileInfo;
        }
        return null;
    }

    public static void main(String[] args) {
        String input = "filename:img_2023-12-09_12:25:37:599887.jpg, filesize:552909";
        FileInfo fileInfo = convertFile(input);
    }
}
